package org.core.tliaswebmanagement.filter;


import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * 过滤器放行前执行顺序：根据类名字母排序，升序。放行后执行顺序：根据类名字母排序，降序
 */

//@WebFilter(urlPatterns = "/filterpath")
@Slf4j
public class DemoFilter implements Filter {
    /**
     * 初始化方法
     * @param filterConfig
     */
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("init初始化过滤器：{}",this.getClass().getName());
    }
    /**
     * 过滤方法
     * 拦截到请求后，会执行此方法，且会执行多次
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("拦截到了请求");
        //放行
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }
}
